<?php
namespace app\index\controller;

//引入系统的数据库类
use think\Db;
//引入系统的控制器类
use think\Controller;
class Index extends Controller
{
    public function index()
    {
        //return '<style type="text/css">*{ padding: 0; margin: 0; } .think_default_text{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_bd568ce7058a1091"></thinkad>';
		//从数据库中读取数据
        $b=10;
		$da=Db::table('sstalink_sensor')->where('id',$b)->column('hooklist');
		foreach($da as $data){	
			$a=(explode(',',$data));
			for($index=0;$index<count($a);$index++){	
			echo base64_decode($a[$index]);
			echo "</br>";
			}       
		} 
		$na=Db::table('sstalink_sensor')->where('id',$b)->column('name');
			foreach($na as $name)
			echo "  /名称  ".$name;echo "</br>";
		$de=Db::table('sstalink_sensor')->where('id',$b)->column('description');
			foreach($de as $description)
			echo "  /描述  ".$description;echo "</br>";
		$dev=Db::table('sstalink_sensor')->where('id',$b)->column('deviceid');
			foreach($dev as $deviceid)
			echo "  /设备ID  ".$deviceid;echo "</br>";
		$typ=Db::table('sstalink_sensor')->where('id',$b)->column('datatype');
			foreach($typ as $datatype)
			echo "  /数据类型  ".$datatype;echo "</br>";
		$type=Db::table('sstalink_sensor')->where('id',$b)->column('showtype');
			foreach($type as $showtype)
			echo "  /显示类型  ".$showtype;echo "</br>";
		$des=Db::table('sstalink_sensor')->where('id',$b)->column('description');
			foreach($des as $description)
			echo "  /传感器类型  ".$description;	
function SendDataByCurl($url,$data=array()){
  //对空格进行转义
  $ch = curl_init();
  //设置选项，包括URL
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch,CURLOPT_TIMEOUT,3); //定义超时3秒钟 
   // POST数据
  curl_setopt($ch, CURLOPT_POST, 1);
  // 把post的变量加上
  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));  //所需传的数组用http_bulid_query()函数处理一下，就ok了
  //执行并获取url地址的内容
  $output = curl_exec($ch);
  $errorCode = curl_errno($ch);
  //释放curl句柄
  curl_close($ch);
  print_r($output);
  if(0 !== $errorCode){
    return false;
  }
  return $output;
}	
        $param = array(
                'name' => $name, 
                'description' => $description,  
                'deviceid' => $deviceid,
				'datatype' => $datatype,
				'showtype' => $showtype,
				'description' => $description,
               );
        $url = "http://127.0.0.1/test.php";
        //通过curl的post方式发送接口请求
       SendDataByCurl($url,$param);
	}
}